package com.peak.distribution.entity.order;

import java.util.Date;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import org.hibernate.annotations.LazyToOne;
import org.hibernate.annotations.LazyToOneOption;

import com.google.common.collect.Lists;
import com.peak.distribution.entity.agent.DisAgent;
import com.peak.distribution.enums.Constants;
import com.peak.distribution.enums.OrderStatus;
import com.peak.distribution.enums.OrderType;
import com.peak.distribution.enums.PayChannel;
import com.peak.spring.boot.api.entity.LogicalDeleteEntity;

import lombok.Data;
import lombok.EqualsAndHashCode;

@Entity
@Table(name = "dis_order")
@Data
@EqualsAndHashCode(callSuper=true)
public class DisOrder extends LogicalDeleteEntity {

	private static final long serialVersionUID = Constants.DISTRIBUTION_VERSION;

	/** 订单号 */
	private String orderNo;

	/** 订单类型 */
	private OrderType orderType;

	/** 订单时间 */
	private Date orderTime;

	/** 支付渠道 */
	private PayChannel payChannel;

	/** 订单状态 */
	private OrderStatus status;

	/** 商品总金额 */
	private Integer goodsFee;
	
	/** 物流费用 */
	private Integer shoppingFee;
	
	/** 订单总费用 */
	private Integer orderFee;

	/** 商品总重量 */
	private Double goodsWeight;

	/** 订单备注 */
	private String remark;

	/** 买家 */
	private DisAgent agent;

	/** 物流 */
	private DisOrderLogistics logistics;

	/** 收件人 */
	private DisOrderReceiver receiver;

	/** 支付日志 */
	private DisOrderPayLog payLog;

	/** 订单商品 */
	private List<DisOrderGoods> goodses = Lists.newArrayList();
	

	@Enumerated(EnumType.STRING)
	public OrderType getOrderType() {
		return orderType;
	}

	@Enumerated(EnumType.STRING)
	public OrderStatus getStatus() {
		return status;
	}

	@Enumerated(EnumType.STRING)
	public PayChannel getPayChannel() {
		return payChannel;
	}

	@ManyToOne
	@JoinColumn(name = "logistics_id")
	@Fetch(FetchMode.SELECT)
	@LazyToOne(LazyToOneOption.PROXY)
	public DisOrderLogistics getLogistics() {
		return logistics;
	}

	@ManyToOne
	@JoinColumn(name = "receiver_id")
	@Fetch(FetchMode.SELECT)
	@LazyToOne(LazyToOneOption.PROXY)
	public DisOrderReceiver getReceiver() {
		return receiver;
	}

	@ManyToOne
	@JoinColumn(name = "pay_log_id")
	@Fetch(FetchMode.SELECT)
	@LazyToOne(LazyToOneOption.PROXY)
	public DisOrderPayLog getPayLog() {
		return payLog;
	}

	@OneToMany(mappedBy = "order")
	@Fetch(FetchMode.SELECT)
	@Cascade(CascadeType.ALL)
	@LazyCollection(LazyCollectionOption.TRUE)
	public List<DisOrderGoods> getGoodses() {
		return goodses;
	}

	@ManyToOne
	@JoinColumn(name = "agent_id")
	@Fetch(FetchMode.SELECT)
	@LazyToOne(LazyToOneOption.PROXY)
	public DisAgent getAgent() {
		return agent;
	}

}
